import { post } from '@/request/http'
import { toString } from '@/utils/utils'
import store from '@/store'
import { setMd5 } from '@/utils/utils'

/**
 * 派车中心用户 接口
 *
 */

/**
 * 获取列表数据   fltUuid -1 写死
 */

export const checkusersysdepartmentList = ({
  PageIndex,
  PageSize,
  usrCode,
  dptId
  // dptFltId = '-1' // 写死 -1
}) =>
  post(
    '/FTKJWLHYPT/system/querySysUserDepartment',
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            usrCode,
            dptId,
            // dptFltId,
            fltUuid: store.state.user.FLT_UUID_DX_H
          }
        },
        Orderby: {},
        PageIndex: {
          FTKJWLHYPT: PageIndex
        },
        PageSize: {
          FTKJWLHYPT: PageSize
        }
      }
    }
  )
/**
 * 新增一行数据
 */

export const addusersysdepartmentList = ({
  usrDpts, // 派车中心id 企业默认-1
  usrCode, // 派车中心用户code
  usrEtpId = '-1', // 上级机构 企业id 写死 -1
  usrName, // 派车中心用户名称
  usrStatus, // 用户状态
  usrRles, // 角色id
  usrPassword,
  usrCompanyUuid = '-1', //企业id
  usrCellphone,
  usrEmail,
  remark = '', // 备注
}) =>
  post(
    '/FTKJWLHYPT/system/addSysUserDepartment',
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            dptId: usrDpts,
            usrCode,
            usrEtpId,
            usrName,
            usrStatus,
            usrRles: usrRles.join(','),
            usrPassword:setMd5(usrPassword),
            usrCompanyUuid,
            usrCellphone,
            usrEmail,
            remark,
            creator: store.state.user.USR_CODE_DX_H,
            fltUuid: store.state.user.FLT_UUID_DX_H
          }
        }
      }
    }
  )
/**
 * 编辑一行数据
 */

export const editusersysdepartment = ({
  usrDpts, // 派车中心id
  uuid, // 派车中心用户id
  dptFltId,
  usrName,
  usrCode,
  usrStatus,
  usrRles,
  usrCompanyUuid = '-1', // 传-1 丁
  usrCellphone,
  usrEmail,
  version, // 版本号
  remark,// 备注
}) =>
  post(
    '/FTKJWLHYPT/system/editSysUserDepartment',
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            dptId: usrDpts,
            uuid,
            dptFltId,
            usrName,
            usrCode,
            usrStatus,
            usrRles: usrRles.join(','),
            usrCompanyUuid,
            usrCellphone,
            usrEmail,
            remark,
            lastmodifier: store.state.user.USR_CODE_DX_H,
            version: toString(version),
            fltUuid: store.state.user.FLT_UUID_DX_H
          }
        }
      }
    }
  )
/**
 * 删除一行数据
 */

export const delusersysdepartment = ({
  uuid,
  version, // 版本号
}) =>
  post(
    '/FTKJWLHYPT/system/delSysUserDepartment',
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            uuid,
            lastmodifier: store.state.user.USR_CODE_DX_H,
            version: toString(version),
            fltUuid: store.state.user.FLT_UUID_DX_H
          }
        }
      }
    }
  )

// 派车中心/组织机构下拉菜单
export const getzuzhiList = () =>
  post(
    '/FTKJWLHYPT/system/selectSysCompany',
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            uuid: '-1',
            fltUuid: store.state.user.FLT_UUID_DX_H
          }
        }
        // Orderby: {},
        // PageIndex: {
        //   FTKJWLHYPT: PageIndex
        //
        // },
        // PageSize: {
        //   FTKJWLHYPT: PageSize
        // }
      }
    }
  )

// 角色下拉菜单
export const queryroles = () =>
  post(
    '/FTKJWLHYPT/system/querySysRoleList',
    {
      Data: {
        Parameters: {
          FTKJWLHYPT: {
            fltUuid: '-1' // 这里固定-1 是因为角色下拉框不区分企业
          }
        }
      }
    }
  )


/* 点击左侧派车中心  */

export const checkdptList = ({
  dptId,
  PageIndex,
  PageSize
}) =>
  post(
    '/FTKJWLHYPT/ControlPath?act=list&actKey=sysDepartment&Section=querySysUserDepartment&SessionId=' +
    store.state.user.SessionId_DX_H,
    {
      Data: {
        Filters: {
          FTKJWLHYPT: {
            dptId,
            dptFltId: '-1',
            fltUuid: store.state.user.fltUuid_DX_H
          }
        },
        Orderby: {},
        PageIndex: {
          FTKJWLHYPT: PageIndex
        },
        PageSize: {
          FTKJWLHYPT: PageSize
        }
      }
    }
  )
